package com.leoman.dao;

import com.leoman.entity.Area;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by 涂奕恒 on 2014/12/4 16:16.
 */
public interface AreaDao extends JpaRepository<Area, Integer>, JpaSpecificationExecutor<Area> {

    @Query("select a from Area a where a.parentId = 0 and a.level = 1 and a.isCut = 0")
    List<Area> findListByParams();

    @Query("select a from Area a where a.parentId = ?1 and a.isCut = 0")
    List<Area> findListByParentId(Integer parentId);

    @Query("select a from Area a where a.isCut = 0")
    List<Area> findList();

    @Query("select a from Area a where a.isCut = 0")
    Page<Area> findList(Pageable pageable);

    @Query("SELECT a FROM Area a WHERE a.isCut = 0 AND a.name = ?1 order by a.id desc")
    List<Area> findListByName(String name);
}